import json


def input_number():
    """获取用户输入的最喜欢的数字,并保存到number.json中"""
    # 获取用户输入的数字
    number = input('What is your favorite number?')
    # 保存数字到number.json
    filename = 'number.json'
    with open(filename, 'w') as f_obj:
        json.dump(number, f_obj)

def output_number():
    """从文件filename中获取用户最喜欢的数字"""
    filename = 'number.json'
    try:
        with open(filename, 'r') as f_obj:
            number = json.load(f_obj)
    except FileNotFoundError:
        return None
    else:
        return number
    
def greet_number():
    """展示数据"""
    number = output_number()
    if number:
        print("Your favorite number is {}.".format(number))
    else:
        input_number()


greet_number()
#input_number()

#number = output_number()
#print("I know your favorite number, It is {}".format(number))
